<template>
  <div v-if="showSuggestions" class="quick-start-suggestions">
    <div class="suggestions-header">
      <h3 class="suggestions-title">
        <font-awesome-icon :icon="['fas', 'lightbulb']" class="title-icon" />
        快速开始建议
      </h3>
      <button @click="hideSuggestions" class="close-btn">
        <font-awesome-icon :icon="['fas', 'times']" />
      </button>
    </div>
    
    <div class="suggestions-content">
      <p class="suggestions-intro">
        {{ isFirstTime ? '欢迎首次使用！' : '欢迎回来！' }}
        以下是一些建议，帮助您更好地开始对话：
      </p>
      
      <div class="suggestion-cards">
        <div 
          v-for="suggestion in suggestions" 
          :key="suggestion.id"
          class="suggestion-card"
          @click="selectSuggestion(suggestion)"
        >
          <div class="card-icon">
            <font-awesome-icon :icon="suggestion.icon" />
          </div>
          <div class="card-content">
            <h4 class="card-title">{{ suggestion.title }}</h4>
            <p class="card-description">{{ suggestion.description }}</p>
            <div class="card-examples">
              <span 
                v-for="example in suggestion.examples.slice(0, 2)" 
                :key="example"
                class="example-tag"
              >
                "{{ example }}"
              </span>
            </div>
          </div>
          <div class="card-arrow">
            <font-awesome-icon :icon="['fas', 'arrow-right']" />
          </div>
        </div>
      </div>
      
      <!-- 或者直接开始对话 -->
      <div class="direct-start">
        <p class="direct-start-text">或者，您也可以直接开始对话：</p>
        <button @click="startDirectChat" class="direct-start-btn">
          <font-awesome-icon :icon="['fas', 'comments']" />
          开始自由对话
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useGuideStore } from '@/stores/guide'

// Props
const props = defineProps({
  autoShow: {
    type: Boolean,
    default: true
  }
})

// Emits
const emit = defineEmits(['suggestion-selected', 'direct-chat-started', 'suggestions-hidden'])

// Store
const guideStore = useGuideStore()

// 响应式数据
const showSuggestions = ref(false)

// 建议数据
const suggestions = ref([
  {
    id: 'mood-check',
    title: '情绪状态分享',
    description: '分享您当前的心情和感受',
    icon: ['fas', 'heart'],
    examples: [
      '我今天感觉有点焦虑',
      '最近心情不太好',
      '我感到很开心'
    ],
    prompt: '我想分享一下我现在的心情和感受...'
  },
  {
    id: 'stress-relief',
    title: '压力缓解咨询',
    description: '寻求压力管理和缓解的建议',
    icon: ['fas', 'leaf'],
    examples: [
      '工作压力很大怎么办',
      '如何放松自己',
      '压力管理技巧'
    ],
    prompt: '我最近压力比较大，希望能得到一些缓解压力的建议...'
  },
  {
    id: 'sleep-issues',
    title: '睡眠问题咨询',
    description: '改善睡眠质量的方法和建议',
    icon: ['fas', 'moon'],
    examples: [
      '失眠怎么办',
      '睡眠质量不好',
      '如何改善睡眠'
    ],
    prompt: '我的睡眠质量不太好，经常失眠，希望能得到一些改善建议...'
  },
  {
    id: 'relationship-advice',
    title: '人际关系咨询',
    description: '处理人际关系问题的建议',
    icon: ['fas', 'users'],
    examples: [
      '与朋友发生矛盾',
      '职场人际关系',
      '家庭关系问题'
    ],
    prompt: '我在人际关系方面遇到了一些困扰，希望能得到一些建议...'
  },
  {
    id: 'self-improvement',
    title: '自我提升指导',
    description: '个人成长和自我提升的方向',
    icon: ['fas', 'chart-line'],
    examples: [
      '如何提升自信',
      '个人成长规划',
      '培养好习惯'
    ],
    prompt: '我想在个人成长方面得到一些指导和建议...'
  },
  {
    id: 'mindfulness',
    title: '正念冥想练习',
    description: '学习正念和冥想技巧',
    icon: ['fas', 'om'],
    examples: [
      '正念冥想入门',
      '如何练习冥想',
      '正念生活方式'
    ],
    prompt: '我想学习一些正念冥想的技巧，帮助自己更好地管理情绪...'
  }
])

// 计算属性
const isFirstTime = computed(() => guideStore.isFirstTime)

// 方法
const selectSuggestion = (suggestion) => {
  console.log('🎯 [QuickStart] 用户选择建议:', suggestion.title)
  emit('suggestion-selected', {
    type: suggestion.id,
    title: suggestion.title,
    prompt: suggestion.prompt
  })
  hideSuggestions()
}

const startDirectChat = () => {
  console.log('💬 [QuickStart] 用户选择直接对话')
  emit('direct-chat-started')
  hideSuggestions()
}

const hideSuggestions = () => {
  showSuggestions.value = false
  // 记录用户已看过建议
  localStorage.setItem('quick-start-suggestions-seen', 'true')
  emit('suggestions-hidden')
}

const shouldShowSuggestions = () => {
  // 检查是否应该显示建议
  const seen = localStorage.getItem('quick-start-suggestions-seen')
  const guideCompleted = localStorage.getItem('user-guide-completed')
  
  // 如果是首次使用或引导刚完成，显示建议
  return !seen || (guideCompleted && !seen)
}

const showSuggestionsPanel = () => {
  showSuggestions.value = true
}

// 生命周期
onMounted(() => {
  if (props.autoShow && shouldShowSuggestions()) {
    // 延迟显示，确保页面加载完成
    setTimeout(() => {
      showSuggestions.value = true
    }, 500)
  }
})

// 暴露方法给父组件
defineExpose({
  showSuggestionsPanel,
  hideSuggestions
})
</script>

<style scoped>
.quick-start-suggestions {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 800px;
  width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 9999;
  animation: slideIn 0.3s ease-out;
}

.suggestions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px 0;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 24px;
}

.suggestions-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 600;
  color: #1f2937;
  margin: 0;
}

.title-icon {
  color: #f59e0b;
}

.close-btn {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: all 0.2s;
}

.close-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

.suggestions-content {
  padding: 0 24px 24px;
}

.suggestions-intro {
  color: #4b5563;
  line-height: 1.6;
  margin-bottom: 24px;
  text-align: center;
}

.suggestion-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.suggestion-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafafa;
}

.suggestion-card:hover {
  border-color: #3b82f6;
  background: #eff6ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.card-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  background: #3b82f6;
  color: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.card-content {
  flex: 1;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #1f2937;
  margin: 0 0 8px 0;
}

.card-description {
  color: #6b7280;
  font-size: 0.875rem;
  margin: 0 0 12px 0;
  line-height: 1.4;
}

.card-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.example-tag {
  background: #dbeafe;
  color: #1e40af;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 12px;
  font-style: italic;
}

.card-arrow {
  flex-shrink: 0;
  color: #9ca3af;
  transition: all 0.2s;
}

.suggestion-card:hover .card-arrow {
  color: #3b82f6;
  transform: translateX(4px);
}

.direct-start {
  text-align: center;
  padding-top: 24px;
  border-top: 1px solid #e5e7eb;
}

.direct-start-text {
  color: #6b7280;
  margin-bottom: 16px;
}

.direct-start-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #10b981;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.direct-start-btn:hover {
  background: #059669;
  transform: translateY(-1px);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .quick-start-suggestions {
    width: 95vw;
    max-height: 90vh;
  }
  
  .suggestion-cards {
    grid-template-columns: 1fr;
  }
  
  .suggestion-card {
    flex-direction: column;
    text-align: center;
  }
  
  .card-content {
    text-align: center;
  }
  
  .card-examples {
    justify-content: center;
  }
}
</style>
